<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">

    <h:body>

        <ui:composition template="/resources/template/template.xhtml">

            <ui:define name="content">

                <h:outputStylesheet library="css" name="printing.css" ></h:outputStylesheet>



                <p:panel header="Manage Patients" styleClass="alignTop"
                         style="height: 600px;">
                    <h:panelGrid columns="2" >

                        <h:form>

                            <p:panel id="panelDetails" header="Details"  >
                                <p:panelGrid columns="3" >
                                    <p:commandButton  ajax="false"
                                                      value="Save" 
                                                      action="#{patientController.saveSelected()}"></p:commandButton>

                                    <p:commandButton  
                                        ajax="false"
                                        value="To Add to Family" 
                                        action="#{patientController.saveSelectedAndToFamily()}"></p:commandButton>

                                    <p:commandButton   ajax="false"
                                                      value="Clear For New Aptient" 
                                                      
                                                      action="#{patientController.prepareAddReg()}"></p:commandButton>


                                </p:panelGrid>

                                <p:tabView  style="width: 600px!important;">

                                    <p:tab title="Patient Details" >

                                        <h:panelGrid id="patientDetail" columns="2" >
                                            <h:panelGrid columns="2" >
                                                <h:outputLabel value="Membership"/>
                                                <p:selectOneMenu value="#{patientController.current.person.membershipScheme}" style="width: 290px;" disabled="#{!webUserController.hasPrivilege('Developers') and patientController.current.id ne null}">
                                                    <!--<f:selectItem itemLabel="Select Membership" />-->
                                                    <f:selectItems value="#{membershipSchemeController.items}" var="t" itemLabel="#{t.name}" itemValue="#{t}"/>
                                                    <f:ajax event="change" execute="@this" render="txtCode" listener="#{patientController.membershipChangeListner}" />
                                                </p:selectOneMenu>

                                                
                                                <h:outputLabel value="Title"/>
                                                <p:selectOneMenu  rendered="#{patientController.current.person ne null}" id="cmbTitle" value="#{patientController.current.person.title}" style="width: 290px;" >
                                                    <f:selectItems value="#{patientController.titles}" var="t" itemLabel="#{t.label}" itemValue="#{t}"/>
                                                </p:selectOneMenu>
                                                <h:outputLabel rendered="#{patientController.current.person eq null}" value=""/>
                                                <h:outputLabel value="Name" for="txtNewPtName"/>
                                                <p:inputText required="true" autocomplete="off"  id="txtNewPtName" value="#{patientController.current.person.name}" 
                                                             style="width: 280px;text-transform:capitalize;">
                                                </p:inputText>

                                                <h:outputLabel value="Code"/>
                                                <p:inputText id="txtCode" value="#{patientController.current.code}" maxlength="8" style="width: 280px;" disabled="#{!webUserController.hasPrivilege('Developers') and patientController.current.person.membershipScheme ne null}"/>

                                                <h:outputLabel  value="PHN"/>
                                                <p:inputText  id="phn"  autocomplete="off"  value="#{patientController.current.phn}" style="width: 280px;"/>
                                                <h:outputLabel value="Sex"/>
                                                <h:outputLabel rendered="#{patientController.current.person eq null}" value=""/>
                                                <p:selectOneMenu rendered="#{patientController.current.person ne null}" id="txtNewSex"  value="#{patientController.current.person.sex}" style="width: 290px;">
                                                    <f:selectItem itemLabel="Select Sex"/>
                                                    <f:selectItems value="#{patientController.sexs}"/>
                                                </p:selectOneMenu>

                                                <h:outputLabel value="Date of Birth"/>
                                                <p:calendar  value="#{patientController.current.person.dob}" id="calNewPtDob" styleClass="dateTimePicker"  navigator="true" pattern="dd/MM/yyyy" >
                                                    <f:ajax event="dateSelect" execute="calNewPtDob" render="year month day" listener="#{patientController.dobChangeListen()}"/>
                                                </p:calendar>

                                                <h:outputLabel value="Age"/>
                                                <h:panelGrid columns="3">
                                                    <p:inputText autocomplete="off"  id="year" style="width: 95px;" value="#{patientController.yearMonthDay.year}">
                                                        <f:ajax event="keyup" execute="@this" render="calNewPtDob" listener="#{patientController.dateChangeListen()}"  />
                                                    </p:inputText>

                                                    <p:inputText autocomplete="off" id="month"   style="width: 80px;" value="#{patientController.yearMonthDay.month}">
                                                        <f:ajax event="keyup" execute="@this" render="calNewPtDob" listener="#{patientController.dateChangeListen()}"  />
                                                    </p:inputText>

                                                    <p:inputText autocomplete="off" id="day"  style="width: 80px;"  value="#{patientController.yearMonthDay.day}">
                                                        <f:ajax event="keyup" execute="@this" render="calNewPtDob" listener="#{patientController.dateChangeListen()}" />
                                                    </p:inputText>

                                                    <p:watermark value="#{patientController.current.ageYears} years" for="year" ></p:watermark>
                                                    <p:watermark value="#{patientController.current.ageMonths} months" for="month" ></p:watermark>
                                                    <p:watermark value="#{patientController.current.ageDays} days" for="day" ></p:watermark>
                                                </h:panelGrid>

                                                <h:outputLabel for="txtNewPtAddress" value="Address"/>
                                                <p:inputTextarea required="true" id="txtNewPtAddress" value="#{patientController.current.person.address}" 
                                                                 style="width: 280px; height: 75px;">
                                                </p:inputTextarea>
    <!--                                                <p:inputText autocomplete="off"  id="txtNewPtAddress" value="#{patientController.current.person.address}">
                                                </p:inputText>-->
                                                <p:outputLabel value="Area"></p:outputLabel>
                                                <p:autoComplete styleClass="mediuminputnew" widgetVar="np" id="acnp" forceSelection="true" 
                                                                value="#{patientController.current.person.area}" 
                                                                completeMethod="#{areaController.completeArea}" 
                                                                var="npt" itemLabel="#{npt.name}" 
                                                                itemValue="#{npt}">
                                                </p:autoComplete>
                                                <h:outputLabel value="Phone"/>
                                                <p:inputMask mask="999-9999999" id="txtNewPtPhone" autocomplete="off" maxlength="11" style="width: 280px;" value="#{patientController.current.person.phone}">
                                                </p:inputMask>
                                                <h:outputLabel value="NIC" />
                                                <p:inputText maxlength="12" value="#{patientController.current.person.nic}" style="width: 280px;"/>
                                                <!--<p:inputMask mask="999999999V" value="#{patientController.current.person.nic}" />-->
                                                <h:outputLabel value="Email"/>
                                                <p:inputText autocomplete="off" value="#{patientController.current.person.email}" style="width: 280px;"/>
                                                <h:outputLabel value="P/F/M No "/>
                                                <p:inputText autocomplete="off" value="#{patientController.current.person.description}" style="width: 280px;"/>
                                                <!--                                                <h:outputLabel value=""/>
                                                                                                <h:outputLabel id="lblPtAge" value="#{patientController.current.age}"/>-->
                                                <h:outputLabel value="Comments"/>
                                                <p:inputTextarea id="txtNewPtComments" value="#{patientController.current.comments}" 
                                                                 style="width: 280px; height: 75px;">
                                                </p:inputTextarea>

                                                <h:outputLabel for="wu" value="Username"/>
                                                <p:inputText required="true" id="wu"
                                                    autocomplete="off" value="#{patientController.current.person.webUser.name}" style="width: 280px;"/>
                                               
<!--                                                <h:outputLabel value="Password"
                                                               for="wp"/>
                                                <p:inputText id="wp" required="true" autocomplete="off" value="#{patientController.password}" style="width: 280px;"/>
                                               -->
                                                
                                            </h:panelGrid>

                                        </h:panelGrid>

                                    </p:tab>

                                    <p:tab title="Photo"  rendered="false">


                                        <p:tab title="Visit Details" >
                                            <p:dataTable id="tblPastVisits" value="#{patientEncounterController.currentPatientEncounters}"
                                                         var="pe"
                                                         >
                                                <p:column headerText="Visit Date" >
                                                    <h:outputLabel value="#{pe.dateTime}" >
                                                        <f:convertDateTime pattern="dd MMMM yyyy - hh:mm a" ></f:convertDateTime>
                                                    </h:outputLabel>
                                                </p:column>
                                                <p:column >
                                                    <h:commandButton value="View" action="/clinical/clinical_new_opd_visit" >
                                                        <f:setPropertyActionListener value="#{pe}" target="#{patientEncounterController.current}" ></f:setPropertyActionListener>
                                                    </h:commandButton>
                                                </p:column>
                                            </p:dataTable>

                                        </p:tab>

                                        <p:panel id="panPhoto" >


                                            <h:panelGrid columns="2"> 
                                                <p:graphicImage  style="border: 1px solid red;" 
                                                                 id="photos" 
                                                                 rendered="#{patientController.current.baImage ne null}"    
                                                                 value="#{patientController.getPhotoByByte(patientController.current.baImage)}"  >
                                                </p:graphicImage>
                                                <h:panelGroup >
                                                    <p:photoCam widgetVar="pc" listener="#{photoCamBean.oncapturePatientPhoto}" update="photos"/>  
                                                    <p:commandButton type="button" value="Capture" 
                                                                     onclick="PF('pc').capture()" />  
                                                </h:panelGroup>




                                            </h:panelGrid>  


                                        </p:panel>


                                    </p:tab>
                                </p:tabView>




                            </p:panel>

                        </h:form>

                    </h:panelGrid>
                </p:panel>



            </ui:define>



        </ui:composition>

    </h:body>
</html>
